$(function(){
	var d = new Date();
	var currentYear=d.getFullYear();
	$('#year').datetimepicker({
		startView: 4,
		minView:4,
		autoclose : true,
		format : 'yyyy'
	});
	$("#year").val(currentYear);
	var t1 = window.setInterval(function() {
		var w = $('#totalCase').width() + "";
		if (w != '0') {
			$('#devicePie').css('width', w/2-40 );
			$('#stationPie').css('width', w/2-40 );
			getCTData();
			window.clearInterval(t1);
		}
	}, 20);
});
function getCTData(){
	var year=$("#year").val();
	$.getJSON('/rest/primerisk/getCTAssessment/'+year, function(result) {
		initDevicePie(result);
		initStationPie(result);
	})
}
function initDevicePie(result){
	var devicePie = new Pie("devicePie");
	var ctsaNum=Object.keys(result["ctsaMap"]).length;
	var data=[["正常",result.totalCT-ctsaNum],["CT饱和",ctsaNum]];
	devicePie.setColors(["#00a65a","#dd4b39"]);
	devicePie.setPie(data);
	devicePie.setPieOuterRadius('50%');
	var opt=devicePie.getOption();
	opt.series[0].label.normal.formatter="{b}{c}({d}%)";
	devicePie.show();
}
function initStationPie(result){
	var stPie = new Pie("stationPie");
	var csStNum=Object.keys(result["csStation"]).length;
	var data=[["正常",result.totalSt-csStNum],["CT饱和",csStNum]];
	stPie.setColors(["#00a65a","#dd4b39"]);
	stPie.setPie(data);
	stPie.setPieOuterRadius('50%');
	var opt=stPie.getOption();
	opt.series[0].label.normal.formatter="{b}{c}({d}%)";
	stPie.show();
	
}
